<!-- templates/posts.html -->
<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>帖子列表</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 1200px;
            margin: 0 auto;
            padding: 20px;
        }

        .post {
            border-bottom: 1px solid #ccc;
            padding: 15px 0;
        }

        .post-images {
            display: flex;
            flex-wrap: wrap;
            gap: 10px;
            margin-top: 10px;
        }

        .post-images img {
            width: 100px;
            height: 100px;
            object-fit: cover;
            border: 1px solid #ddd;
            border-radius: 4px;
        }

        .pagination {
            margin-top: 30px;
            text-align: center;
        }

        .pagination a {
            margin: 0 5px;
            text-decoration: none;
            padding: 8px 12px;
            border: 1px solid #ccc;
        }

        .pagination a:hover {
            background-color: #f0f0f0;
        }

        .pagination .current {
            background-color: #007bff;
            color: white;
            border-color: #007bff;
        }
    </style>
</head>
<body>
<h1>帖子列表</h1>

{% for post in posts %}
    <div class="post">
        <div>{{ post.content|safe }}</div>

        <!-- 图片展示区域 -->
        <div class="post-images">
            {% if post.image %}
                {% set images = post.image|json_loads %}
                {% for img in images %}
                    <img src="{{ img }}" alt="帖子图片">
                {% endfor %}
            {% endif %}

        </div>

        <div><strong>{{ post.publish_time.strftime('%Y-%m-%d %H:%M') }}</strong></div>
    </div>
{% endfor %}

<!-- 分页导航 -->
<div class="pagination">
    {% if page > 1 %}
        <a href="{{ url_for('web.posts', page=page-1) }}">上一页</a>
    {% else %}
        <span class="current">上一页</span>
    {% endif %}

    <span>第 {{ page }} 页 / 共 {{ (total // per_page) + (1 if total % per_page else 0) }} 页</span>

    {% if page * per_page < total %}
        <a href="{{ url_for('web.posts', page=page + 1) }}">下一页</a>
    {% else %}
        <span class="current">下一页</span>
    {% endif %}
</div>
</body>
</html>
